package cn.com.sinosoft.exam.dao;

import cn.com.sinosoft.exam.model.Patient;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @Author:刘韵琴
 * @Date:2019/1/26 22:23
 * @Description :
 */
@org.apache.ibatis.annotations.Mapper
public interface PatientMapper2 extends Mapper<Patient> {

    /**
     * 查询近一个月的记录
     * @param orgcode
     * @return
     */
    @Select("SELECT p.* FROM t_follow f,t_patient p WHERE f.patient_id=p.id  AND DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= DATE(f.dt_follow) \n" +
            " AND p.orgcode = #{orgcode}" +
            "     ORDER BY f.dt_follow")
    List<Patient> findByPage(@Param("orgcode") String orgcode);

    /**
     * 更新建档时间
     * @param orgcode
     * @return
     */
    @Update("  UPDATE   t_patient SET dt_fill='2019-01-01' WHERE dt_fill='2018-01-01'\n" +
            "AND orgcode=#{orgcode} AND id  IN (SELECT patient_id FROM t_follow) ;")
    int updateByOrgcode(@Param("orgcode") String orgcode);


}
